package com.fa;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * Hello world!
 *
 */
@SpringBootApplication
@Slf4j
public class FastAdminApp {
    public static void main(String[] args) {
        SpringApplication app = new SpringApplication(FastAdminApp.class);
        ConfigurableApplicationContext context = app.run(args);
        ConfigurableEnvironment env = context.getEnvironment();

        String protocol = "http";
        if (env.getProperty("server.ssl.key-store") != null) {
            protocol = "https";
        }

        try {
            log.info("\n------------------------------------------------------\n\t" +
                    "Application '{}' is running! Access URLs:\n\t" +
                    "Local: \t\t{}://localhost:{}\n\t" +
                    "External: \t{}://{}:{}\n\t" +
                    "Profile(s): \t{}\n" +
                    "------------------------------------------------------",
                    env.getProperty("spring.application.name"),
                    protocol,
                    env.getProperty("server.port"),
                    protocol,
                    InetAddress.getLocalHost().getHostAddress(),
                    //env.getProperty("server.address"),
                    env.getProperty("server.port"),
                    env.getActiveProfiles()
                    );
        } catch (UnknownHostException e) {
            log.error("项目启动异常！");
            throw new RuntimeException(e);
        }
    }
}
